<?php
/**
 * XuYuan Project
 *
 * @package	XueYuan 
 * @author	Jiuchi Team
 * @since	Version 1.0.0
 * @filesource
 */
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * My circle view
 * @author Wayne Yu
 */
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <?php $this->load->view('common/head');?>
	<!-- Page special css -->
    <link rel="stylesheet" type="text/css" href="/assets/css/index.css">
    <link rel="stylesheet" type="text/css" href="/assets/css/mycenter.css">
    <link rel="stylesheet" type="text/css" href="/assets/css/mycircle.css">
</head>
<body>
    <div class="navigation">
		<?php $this->load->view('common/navigation');?> 
    </div>
    <div class="wrapper">
        <div class="main-content">
			<div class="main-content-inner">
                <div class="home-list">
                    <div class="home-list-title">
						<button class="btn-label active">我的圈子</button>
                        <button class="btn-label" onclick="window.location = '<?php echo site_url('circle/all')?>'">全部圈子</button>
                       	<div id="btn-createCircle" class="fancybox fancybox.iframe btn-create-circle">创建圈子</div>
                    </div>
                    <div class="home-list-content clearfix">
                        <div id="ep-tips" class="ep-tips">
                            <span>你暂时没有关注任何圈子。</span>
                        </div>
                        <ul id="circlesMore">
                            <li class="circle-item">
                                <div class="rep">
                                    <div class="rep-header clearfix">
                                        <div class="rep-title ellipsis fl circle_name">
                                        </div>
                                        <div class="action fr">                         
                                        </div>
                                        <div class="circle_id hidden"></div>     
                                    </div>
                                    <div class="rep-content-wrapper">
                                        <div class="rep-content clearfix">
                                            <div class="rep-cir-img circle_img">
                                            </div>
                                            <div class="rep-cir-note circle_topics">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <a href="#" class="btn-white btn-more">查看更多</a>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer">
			<?php $this->load->view('common/footer');?>
        </div>
    </div>

    <!-- Page special scripts -->
    <script type="text/javascript" src="/assets/js/jquery.more.js"></script>
	<script type="text/javascript">
		$(document).ready(function () {
            $("#btn-createCircle").fancybox({
                href:"<?php echo site_url('circle/create')?>",
                minWidth:500,
                minHeight:300,
                padding:0,
            })
            $('#circlesMore').more({
            'address': '<?php echo site_url('circle/getUserCircles')?>',
            'template': '.circle-item',
            'trigger': '.btn-more',
            'defaultshow' :'#ep-tips',
            });
	    });

/* 关注圈子 */
        function btnConcern(ele) {
            var ele =$(ele);
            $.ajax({
                type: 'post',
                url: '<?php echo site_url('circle/userAction')?>',
                data: {
                    action : "concern",
                    circle_id : ele.parent().parent().children().last().text(),           
                },
                dataType: 'json',
                success: function(data) {
                    if (data.StatusCode == 200) {
                        alert("关注成功");
                        var newElement = '<div class="rep-concern fr" onclick="btnUnConcern(this)">取消关注</div>';
                        ele.prop("outerHTML",newElement);
                    } else if (data.StatusCode == 300) {
                        alert(data.Msg);
                    }
                }
            });
        }

/* 取消关注 */ 
        function btnUnConcern(ele) {
            var a=confirm("你确定取消关注么？")
            if(a=true){
                var ele =$(ele);
                $.ajax({
                    type: 'post',
                    url: '<?php echo site_url('circle/userAction/')?>',
                    data: {
                        action : "unconcern",
                        circle_id : ele.parent().parent().children().last().text(),           
                    },
                    dataType: 'json',
                    success: function(data) {
                        if (data.StatusCode == 200) {
                            alert("取关成功");
                            var eleParent =ele.parent();
                            var newElement = '<div class="rep-concern active fr" onclick="btnConcern(this)">关注圈子</div><div class="rep-concern active fr" onclick="btnJoin(this)">申请加入</div>';
                            eleParent.html(newElement);
                        } else if (data.StatusCode == 300) {
                            alert(data.Msg);
                        }
                    }
                });
            }else{
                return;
            }            
        }

/* 申请加入 */ 
        function btnJoin(ele) {
            var ele =$(ele);
            $.ajax({
                type: 'post',
                url: '<?php echo site_url('circle/userAction/')?>',
                data: {
                    action : "join",
                    circle_id : ele.parent().parent().children().last().text(),           
                },
                dataType: 'json',
                success: function(data) {
                    if (data.StatusCode == 200) {
                        alert("申请成功，并已经关注。");
                        var eleParent =ele.parent();
                        var newElement = '<div class="rep-concern fr" onclick="btnConcern(this)">取消关注</div><div class="rep-concern fr" onclick="btnWaitCheck(this)">待审核</div>';
                        eleParent.html(newElement);
                    } else if (data.StatusCode == 300) {
                        alert(data.Msg);
                    }
                }
            });
        }

/* 待审核状态 */ 
        function btnWaitCheck(ele) {
            var ele =$(ele);
            alert("你的申请正在审核中，请耐心等待。")
        };
/* 退出圈子 */ 
        function btnQuit(ele) {
            var a=confirm("你确定退出圈子么，同时你也将取消关注。")
            if(a=true){
                var ele =$(ele);
                $.ajax({
                    type: 'post',
                    url: '<?php echo site_url('circle/userAction/')?>',
                    data: {
                        action : "quit",
                        circle_id : ele.parent().parent().children().last().text(),           
                    },
                    dataType: 'json',
                    success: function(data) {
                        if (data.StatusCode == 200) {
                            alert("退出成功");
                            var newElement='<div class="rep-concern active fr" onclick="btnJoin(this)">申请加入</div>';
                            ele.prop("outerHTML",newElement);
                        } else if (data.StatusCode == 300) {
                            alert(data.Msg);
                        }
                    }
                });    
            }else{
                return;
            }            
        }
	</script>
</body>
</html>

